<?php
if (!headers_sent()) {
    ob_start();
}
session_start();
// 用户存在性校验
if (isset($_SESSION['username'])) {
    $userData = @file_get_contents(USER_AUTH_URL);
    if ($userData) {
        $users = json_decode($userData, true)['users'];
        $exists = false;
        foreach ($users as $user) {
            if ($user['username'] === $_SESSION['username']) {
                $exists = true;
                break;
            }
        }
        if (!$exists) {
            session_unset();
            session_destroy();
            header('Location: login.php?error=notfound');
            exit();
        }
    }
}
require_once 'includes/theme.php';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>快递查询系统</title>
    <link rel="icon" href="kuaidi.ico" type="image/x-icon">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/global.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: <?php echo get_theme_color('primary'); ?>;
            --secondary-color: <?php echo get_theme_color('secondary'); ?>;
            --success-color: <?php echo get_theme_color('success'); ?>;
            --danger-color: <?php echo get_theme_color('danger'); ?>;
            --warning-color: <?php echo get_theme_color('warning'); ?>;
            --info-color: <?php echo get_theme_color('info'); ?>;
            --light-color: <?php echo get_theme_color('light'); ?>;
            --dark-color: <?php echo get_theme_color('dark'); ?>;
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="index.php">快递查询系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto">
                    <?php if(isset($_SESSION['user_id'])): ?>
                        <li class="nav-item">
                            <span class="nav-link disabled" style="color:#fff;opacity:.85;">
                                <?php echo isset($_SESSION['username']) ? htmlspecialchars($_SESSION['username']) : '未知用户'; ?>
                            </span>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="history.php">查询历史</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="logout.php">退出登录</a>
                        </li>
                    <?php else: ?>
                        <li class="nav-item">
                            <a class="nav-link" href="login.php">登录</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="https://blog.lahong.top:8888/!/register.php" target="_blank">注册</a>
                        </li>
                    <?php endif; ?>
                </ul>
            </div>
        </div>
    </nav>
    <div class="container"> 